//
//  HZcgInline.h
//  PublishTest
//
//  Created by 刘华舟 on 15/4/14.
//  Copyright (c) 2015年 云图. All rights reserved.
//

#import <Foundation/Foundation.h>

#pragma mark - 获取CGRect系列的 坐标值：
CG_INLINE CGRect CGRectWith(CGPoint original,CGSize size){
    return CGRectMake(original.x,original.y,size.width,size.height);
}
#pragma mark - 视图底部坐标:
CG_INLINE CGFloat GetEndYWithView(UIView *view){
    return CGRectGetHeight(view.frame)+view.frame.origin.y;
}
#pragma mark - 视图的右边尾部坐标:
CG_INLINE CGFloat GetEndXWithView(UIView *view){
    return CGRectGetWidth(view.frame)+view.frame.origin.x;
}
#pragma mark - 视图的尾部坐标:
CG_INLINE CGFloat GetEndYWithFrame(CGRect frame){
    return CGRectGetHeight(frame)+frame.origin.y;
}
#pragma mark - 视图的右边尾部坐标:
CG_INLINE CGFloat GetEndXWithFrame(CGRect frame){
    return CGRectGetWidth(frame)+frame.origin.x;
}

CG_INLINE CGFloat GetYWithView(UIView *view){
    return view.frame.origin.y;
}
CG_INLINE CGFloat GetXWithView(UIView *view){
    return view.frame.origin.x;
}
CG_INLINE CGFloat GetYWithRect(CGRect rect){
    return rect.origin.y;
}
CG_INLINE CGFloat GetXWithRect(CGRect rect){
    return rect.origin.x;
}

#pragma mark - 根据三元素返回UIColor对象
CG_INLINE UIColor * ColorWithRGB(CGFloat red,CGFloat green,CGFloat blue){
    return [UIColor colorWithRed:red/255 green:green/255 blue:blue/255 alpha:1];
}


#pragma mark - 检查是否是一个对象
CG_INLINE BOOL checkValue(id object){
    if (object!=[NSNull null] && object!=NULL && object!=nil && object!=Nil) {
        return YES;
    }
    else{
        return NO;
    }
}

#pragma mark - 检查是否是一个非空数组
CG_INLINE BOOL checkList(id array){
    if (checkValue(array)) {
        if ([array isKindOfClass:[NSArray class]]) {
            if ([array count]) {
                return YES;
            }
        }
    }
    return NO;
    
}

#pragma mark - 检查是否是一个非空合集
CG_INLINE BOOL checkSet(id set){
    if (checkValue(set)) {
        if ([set isKindOfClass:[NSSet class]]) {
            if ([set count]) {
                return YES;
            }
        }
    }
    return NO;
    
}

#pragma mark - 检查是否是一个非空字典
CG_INLINE BOOL checkDict(id dict){
    if (checkValue(dict)) {
        if ([dict isKindOfClass:[NSDictionary class]]&&[[dict allKeys]count]) {
            //if ([dict isKindOfClass:[NSDictionary class]]) {
            
            return YES;
        }
    }
    
    return NO;
}

//返回一个安全的字符串
CG_INLINE NSString * getSafeStringWithObject(id object){
    NSString *finnalString=object;
    if (!checkValue(object)) {
        finnalString=@"";
    }
    else if(![finnalString isKindOfClass:[NSString class]]) {
        finnalString = [NSString stringWithFormat:@"%@",finnalString];
    }
    
    return finnalString;
}
#pragma mark - 安全的从指定数组中取得第index个数据，安全的意思是不会崩溃
CG_INLINE id getSafeObjectAtIndex(int index,NSArray* sourceList){
    if (!checkList(sourceList)) {
        return nil;
    }
    id targetObject =nil;
    
    if(index>=0 && index<=sourceList.count-1){
        targetObject= [sourceList objectAtIndex:index];
    }
    
    return targetObject;
}

//检查指定字符串是否是一个非空字符串
CG_INLINE BOOL checkString(id string){
    if (checkValue(string)) {
        if ([string isKindOfClass:[NSString class]] && ![string isEqualToString:@""]) {
            return YES;
        }
    }
    
    return NO;
}